<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Delete extends CI_Controller
{
	
	function __construct()
	{
		parent::__construct();
	}
	
	function index()
	{
	}
		
	function track($fid)
	{
		$this->load->library("session_manager");
		$sm = $this->session_manager;
		$this->load->database();
		$this->load->model("Gps_log_files");
		$this->load->model("Gps_log_source");

		$result = $this->Gps_log_files->get_log_file($sm->user["uid"],$fid);
		if ($result)//有记录
		{
			if ($this->Gps_log_files->delete_log_file($sm->user["uid"],$fid))
			{
				@unlink($this->_build_path($sm->user["uid"],$result->gen_time,"kml",false)."/".$result->filename.".kml");
				@unlink($this->_build_path($sm->user["uid"],$result->gen_time,"svg",false)."/".$result->filename."_spd.svg");
				@unlink($this->_build_path($sm->user["uid"],$result->gen_time,"svg",false)."/".$result->filename."_alt.svg");
				@unlink($this->_build_path($sm->user["uid"],$result->gen_time,"svg",false)."/".$result->filename."_sat.svg");
				$this->Gps_log_source->add_remove_tracks($sm->user["uid"], $result->sid, false);
				echo '<script language="Javascript">$("#track_'.$fid.'").remove();</script>';
			}			
		}
		else //无记录
		{
			
		}
		
	}
	
	
	function _build_path($uid,$timestamp,$type,$url=true)
	{
		$dirs = array(
			$uid,
			$type,
			@date("Y", $timestamp),
			@date("m", $timestamp),
			@date("d", $timestamp)
		);
		
		if ($url) //生成URL或实际路径
		    $path = base_url().STORAGE_PATH;
		else
		    $path = base_dir().STORAGE_PATH;
		foreach ($dirs as $dir){
			$path .="/".$dir;
		}
				
		return $path;
	}

	
}
?>